package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.Doctorconsultations;
import com.qf.entity.Doctors;
import com.qf.service.doctorconsultations.DoctorService;
import com.qf.service.doctorconsultations.DoctorconsultationsService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import com.qf.util.R;

import java.util.List;

/**
 * (Doctorconsultations)表控制层
 *
 * @author makejava
 * @since 2024-12-02 20:57:08
 */
@RestController
@RequestMapping("/consultations")
public class DoctorconsultationsController {
    /**
     * 服务对象
     */
    @Autowired
    private DoctorconsultationsService doctorconsultationsService;

    @Autowired
    private DoctorService doctorService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @GetMapping("/list")
    public R queryByPage(Doctorconsultations doctorconsultations) {

        PageHelper.startPage(doctorconsultations.getPageNum(), doctorconsultations.getPageSize());

        List<Doctorconsultations> list = doctorconsultationsService.list(doctorconsultations);

        PageInfo<Doctorconsultations> pageInfo = new PageInfo<>(list);

        return R.ok(pageInfo);
    }

    /**
     * 查询医生
     */
    @GetMapping("/doctorList")
    public R doctorList(Doctors doctors) {
        //PageHelper.startPage(doctors.getPageNum(), doctors.getPageSize());

        List<Doctors> list = doctorService.doctorList(doctors);

        //PageInfo<Doctors> pageInfo = new PageInfo<>(list);

        return R.ok(list);
    }

    /**
     * 新增数据
     *
     * @param doctorconsultations 实体
     * @return 新增结果
     */
    @PostMapping("/add")
    public R add(@RequestBody Doctorconsultations doctorconsultations) {
        this.doctorconsultationsService.insert(doctorconsultations);
        return R.ok();
    }

    /**
     * 编辑数据
     *
     * @param doctorconsultations 实体
     * @return 编辑结果
     */
    @PostMapping("/edit")
    public R edit(@RequestBody Doctorconsultations doctorconsultations) {
        return R.ok(this.doctorconsultationsService.update(doctorconsultations));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("/del")
    public R deleteById(Integer id) {
        return R.ok(this.doctorconsultationsService.deleteById(id));
    }

}

